<template>
  <div id="app">
    <vNav></vNav>
    <vLoading v-show="$root.$data.bLoading"></vLoading>
    <router-view></router-view>
    <vFooter></vFooter>
    <span class="BackTop" v-if="showBack" @click="BackTops">
      <img src="./assets/img/arrow_top.png" alt="" srcset="">
    </span>
  </div>
</template>

<script>
import vFooter from '@/components/Footer'
import vNav from '@/components/Nav'
import vLoading from '@/components/Loading'
export default {
  data(){
    return{
      showBack:false,
    }
  },
  name: 'App',
  components:{
    vFooter,
    vNav,
    vLoading
  },
  methods:{
    handleScroll() {
      var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      if(scrollTop > 10){
        this.showBack = true;
      }else if(scrollTop == 0){
         this.showBack = false;
      }
    },
    BackTops(){
      var toTop = document.getElementsByClassName('BackTop');
      var timer = setInterval(() => {
        var scrollTop= document.documentElement.scrollTop||document.body.scrollTop;
        var ispeed=Math.floor(-scrollTop/6);
        if(scrollTop==0){
          clearInterval(timer);
        };
        document.documentElement.scrollTop=document.body.scrollTop=scrollTop+ispeed;
      },10);
		}
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll, true);
   
  },
  destroyed() {
    window.removeEventListener("scroll", this.handleScroll);
  }
}

</script>
<style>
html,body{
  margin: 0;
  padding: 0;
  min-width: 1366px;
  overflow: auto;
}
#app {
  font-family: 'Arial';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
.BackTop{
  width: 50px;
  height: 50px;
  border-radius: 50%;
  position: fixed;
  bottom: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  right: 30px;
  z-index: 1000;
  color: #fff;
  background: #FFE300;
  cursor: pointer;
}
</style>
